---
title: Read PDF version
summary: Extracts the PDF version token from the document header.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-17
library: PdfAPI.Core
reference_type: package
operation_id: OP-04
trigger: PdfClientService.Version(byte[]) invoked
---

# Read PDF version

This operation reports the `%PDF-d.d` version token declared in a PDF's header bytes.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-04 |
| **Trigger** | Caller invokes `Version(byte[] file)` |
| **Inputs** | PDF bytes |
| **Outputs** | Version string (e.g., `"1.7"`), or `""` when not found |
| **Primary components** | `PdfAPI.Core.PdfClientService.Version` |
| **Entry point** | `PdfAPI.Core\Services\PdfClientService.cs` |

## Steps

1. Run [Validate PDF bytes](op-01-validate-pdf-bytes.md) to guard the input. ([BR-01](../business-rules.md#br-01-pdf-signature-validation), [BR-02](../business-rules.md#br-02-null-bytes-are-never-a-pdf), [BR-03](../business-rules.md#br-03-invalid-pdf-input-aborts-with-pdfexception))
2. Decode the bytes as ASCII, require length ≥ 8 and the `%PDF` magic bytes. ([BR-01](../business-rules.md#br-01-pdf-signature-validation))
3. Match `%PDF-(?<version>\d+\.\d+)` and return the captured version. ([BR-08](../business-rules.md#br-08-pdf-version-extraction))
4. Return an empty string when no match is found. ([BR-08](../business-rules.md#br-08-pdf-version-extraction))

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start(["Version(bytes)"]) --> Guard["OP-01: ValidatePdf"]
	Guard --> Header{length >= 8 and<br>%PDF magic bytes?}
	Header -->|No| Empty1(["Return \"\""])
	Header -->|Yes| Regex["Match %PDF-(version)"]
	Regex -->|Match| Return([Return version string])
	Regex -->|No match| Empty2(["Return \"\""])
```

## Failure and edge-case behavior
- Invalid PDF input aborts via `PdfException` at the guard step ([BR-03](../business-rules.md#br-03-invalid-pdf-input-aborts-with-pdfexception)) before any version parsing occurs.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Security and authorization](../security-authorization.md)

## Sources
- `PdfAPI.Core\Services\PdfClientService.cs`
